home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / compiler / Globals.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  6.4 KB  |  272 lines  |  [TEXT/R*ch]

  1. local
  2.   open Fnlib Mixture Const Smlprim;
  3. in
  4.  
  5. (* Internally, a global is represented by its fully qualified name,
  6.    plus associated information. *)
  7.  
  8. type 'a global =
  9. {
  10.   info: 'a,               (* Description *)
  11.   qualid: QualifiedIdent  (* Full name *)
  12. };
  13.  
  14. datatype TyNameEqu = FALSEequ | TRUEequ | REFequ;
  15.  
  16. datatype TyStr  =
  17.     NILts
  18.   | TYPEts of TypeVar list * Type
  19.   | DATATYPEts of int
  20.   | REAts of TyName
  21.  
  22. and Type =
  23.     VARt of TypeVar
  24.   | ARROWt of Type * Type
  25.   | CONt of Type list * TyName
  26.   | RECt of { fields: (Lab * Type) list, rho: RowType } ref
  27.  
  28. and TypeVarKind =
  29.     Explicit of string
  30.   | NoLink
  31.   | LinkTo of Type
  32.  
  33. and RowTypeKind =
  34.     NILrow
  35.   | VARrow of RowVar
  36.   | LINKrow of RowType
  37.   | FIELDrow of Lab * Type * RowType
  38.  
  39. and TypeScheme = TypeScheme of
  40. {
  41.   tscParameters: TypeVar list,
  42.   tscBody: Type
  43. }
  44.  
  45. withtype TyName =
  46. {
  47.   tnArity: int,
  48.   tnEqu: TyNameEqu,
  49.   tnStamp: int,
  50.   tnStr: TyStr
  51. } ref global
  52.  
  53. and ConInfo =
  54. {
  55.   conArity: int,
  56.   conIsGreedy: bool,
  57.   conSpan: int,
  58.   conTag: int,
  59.   conType : TypeScheme
  60. } ref
  61.  
  62. and ExConInfo =
  63. {
  64.   exconArity: int,
  65.   exconIsGreedy: bool,
  66.   exconTag : (QualifiedIdent * int) option
  67. } ref
  68.  
  69. and TypeVar =
  70. {
  71.   tvEqu : bool,
  72.   tvImp : bool,
  73.   tvKind : TypeVarKind,
  74.   tvLevel : int,
  75.   tvOvl : bool
  76. } ref
  77.  
  78. and RowType = RowTypeKind ref
  79.  
  80. and RowVar =
  81. {
  82.   rvEqu : bool,
  83.   rvImp : bool,
  84.   rvLevel : int
  85. } ref
  86. ;
  87.  
  88. type RecType = { fields: (Lab * Type) list, rho: RowType } ref;
  89.  
  90. type ConEnv = ConInfo global list;
  91.  
  92. datatype OvlType =
  93.     REGULARo                (* Non-overloaded                *)
  94.   | OVL1NNo                (* numtext -> num                *)
  95.   | OVL1NSo                (* numtext -> string             *)
  96.   | OVL2NNBo                (* numtext * numtext -> bool     *)
  97.   | OVL2NNNo                (* num * num -> num              *)
  98.   | OVL1TXXo                (* printVal: pseudopoly 'a -> 'a *)
  99.   | OVL1TPUo                (* installPP: pseudopoly         *)
  100.   | OVL2EEBo                            (* =, <>: ''a * ''a -> bool      *)
  101. ;
  102.  
  103. type PrimInfo =
  104. {
  105.   primArity: int,
  106.   primOp: SMLPrim
  107. };
  108.  
  109. datatype ConStatusDesc =
  110.     VARname of OvlType
  111.   | PRIMname of PrimInfo
  112.   | CONname of ConInfo
  113.   | EXNname of ExConInfo
  114.   | REFname
  115. ;
  116.  
  117. type ConStatus = ConStatusDesc global;
  118.  
  119. type ConBasis = (string, ConStatus) Env;
  120. type TyEnv  = (string, TyName) Env;
  121. type VarEnv = (string, TypeScheme) Env;
  122.  
  123. datatype InfixStatus =
  124.     NONFIXst
  125.   | INFIXst of int
  126.   | INFIXRst of int
  127. ;
  128.  
  129. type InfixBasis = (string, InfixStatus) Env;
  130.  
  131. (* Updaters *)
  132.  
  133. fun setTnStamp r new_stamp =
  134.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  135.     r := { tnStamp=new_stamp, tnArity=arity, tnEqu=equ, tnStr=str }
  136.   end;
  137.  
  138. fun setTnEqu r new_equ =
  139.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  140.     r := { tnStamp=stamp, tnArity=arity, tnEqu=new_equ, tnStr=str }
  141.   end;
  142.  
  143. fun setTnStr r new_str =
  144.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  145.     r := { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=new_str }
  146.   end;
  147.  
  148. fun setConArity r new_arity =
  149.   let val { conArity=arity, conIsGreedy=isGreedy,
  150.             conTag=tag, conSpan=span, conType=typ }
  151.           = !r
  152.   in r :=
  153.     { conArity=new_arity, conIsGreedy=isGreedy,
  154.       conTag=tag, conSpan=span, conType=typ }
  155.   end;
  156.  
  157. fun setConIsGreedy r new_isGreedy =
  158.   let val { conArity=arity, conIsGreedy=isGreedy,
  159.             conTag=tag, conSpan=span, conType=typ }
  160.           = !r
  161.   in r :=
  162.     { conArity=arity, conIsGreedy=new_isGreedy,
  163.       conTag=tag, conSpan=span, conType=typ }
  164.   end;
  165.  
  166. fun setConTag r new_tag =
  167.   let val { conArity=arity, conIsGreedy=isGreedy,
  168.             conTag=tag, conSpan=span, conType=typ }
  169.           = !r
  170.   in r :=
  171.     { conArity=arity, conIsGreedy=isGreedy,
  172.       conTag=new_tag, conSpan=span, conType=typ }
  173.   end;
  174.  
  175. fun setConSpan r new_span =
  176.   let val { conArity=arity, conIsGreedy=isGreedy,
  177.             conTag=tag, conSpan=span, conType=typ }
  178.           = !r
  179.   in r :=
  180.     { conArity=arity, conIsGreedy=isGreedy,
  181.       conTag=tag, conSpan=new_span, conType=typ }
  182.   end;
  183.  
  184. fun setConType (r : ConInfo) new_typ =
  185.   let val { conArity=arity, conIsGreedy=isGreedy,
  186.             conTag=tag, conSpan=span, conType=typ }
  187.           = !r
  188.   in r :=
  189.     { conArity=arity, conIsGreedy=isGreedy,
  190.       conTag=tag, conSpan=span, conType=new_typ }
  191.   end;
  192.  
  193. fun setExConArity r new_arity =
  194.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  195.   in r :=
  196.     { exconArity=new_arity, exconIsGreedy=isGreedy, exconTag=tag }
  197.   end;
  198.  
  199. fun setExConIsGreedy r new_isGreedy =
  200.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  201.   in r :=
  202.     { exconArity=arity, exconIsGreedy=new_isGreedy, exconTag=tag }
  203.   end;
  204.  
  205. fun setExConTag r new_tag =
  206.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  207.   in r :=
  208.     { exconArity=arity, exconIsGreedy=isGreedy, exconTag=new_tag }
  209.   end;
  210.  
  211. fun setTvKind r new_kind =
  212.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  213.           = !r
  214.   in r :=
  215.     { tvKind=new_kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  216.   end;
  217.  
  218. fun setTvLevel r new_level =
  219.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  220.           = !r
  221.   in r :=
  222.     { tvKind=kind, tvLevel=new_level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  223.   end;
  224.  
  225. fun setTvEqu r new_equ =
  226.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  227.           = !r
  228.   in r :=
  229.     { tvKind=kind, tvLevel=level, tvEqu=new_equ, tvImp=imp, tvOvl=ovl }
  230.   end;
  231.  
  232. fun setTvImp r new_imp =
  233.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  234.           = !r
  235.   in r :=
  236.     { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=new_imp, tvOvl=ovl }
  237.   end;
  238.  
  239. fun setTvOvl r new_ovl =
  240.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  241.           = !r
  242.   in r :=
  243.     { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=new_ovl }
  244.   end;
  245.  
  246. fun setRtFields r new_fields =
  247.   let val { fields=fields, rho=rho } = !r in
  248.     r := { fields=new_fields, rho=rho }
  249.   end;
  250.  
  251. fun setRtRho r new_rho =
  252.   let val { fields=fields, rho=rho } = !r in
  253.     r := { fields=fields, rho=new_rho }
  254.   end;
  255.  
  256. fun setRvEqu r new_equ =
  257.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  258.     r := { rvEqu=new_equ, rvImp=imp, rvLevel=level }
  259.   end;
  260.  
  261. fun setRvImp r new_imp =
  262.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  263.     r := { rvEqu=equ, rvImp=new_imp, rvLevel=level }
  264.   end;
  265.  
  266. fun setRvLevel r new_level =
  267.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  268.     r := { rvEqu=equ, rvImp=imp, rvLevel=new_level }
  269.   end;
  270.  
  271. end;
  272.